import Vue from 'vue'
import VueRouter from 'vue-router'
import Index from '../views/mall/Index'
import Login from '../views/Login'
import Mall from '../views/Mall'
import Register from "../views/Register";
import Cart from "../views/mall/Cart";
import Product from "../views/mall/Product";
import AllGoods from "../views/mall/AllGoods";
import OrderList from "../views/mall/OrderList";
import Brand from "../views/mall/Brand";
import Species from "../views/mall/Species";
import Payment from "../views/Payment";
import Supply from "../views/Supply";
import PersonalCenter from "../views/PersonalCenter";


Vue.use(VueRouter)

const routes = [
  {
    path: "/login",
    name: "login",
    component: Login
  },
  {
    path: "/register",
    name: "register",
    component: Register
  },
  {
    path: "/personal-center",
    name: "personal-center",
    component: PersonalCenter
  },
  {
    path: "/supply",
    name: "supply",
    component: Supply
  },
  {
    path: "/payment/:id",
    component: Payment
  },
  {
    path: "/",
    redirect: "/mall/index"
  },
  {
    path: "/mall",
    component: Mall,
    children: [
      {
        path: "index",
        name: "index",
        component: Index,
        meta: {
          tree: ['list']
        }
      },
      {
        path: "all-goods",
        name: "all-goods",
        component: AllGoods,
        meta: {
          tree: ['list']
        }
      },
      {
        path: "brand/:id",
        name: "brand",
        component: Brand,
        meta: {
          tree: ['list']
        }
      },
      {
        path: "species/:id",
        name: "species",
        component: Species,
        meta: {
          tree: ['list']
        }
      },
      {
        path: "product/:id",
        name: "product",
        component: Product,
        meta: {
          tree: ['list', 'detail'],
        }
      },
      {
        path: "cart",
        name: "cart",
        component: Cart,
        meta: {
          tree: ['cart'],
        }
      },
      {
        path: "orders",
        name: "orders",
        component: OrderList,
        meta: {
          tree: ['orders'],
        }
      },
    ]
  },
  {
    path: "*",
    redirect: "/mall/index"
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
